<?php require_once('Connections/sepolwan_connect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_ambil_berita = "-1";
if (isset($_GET['idberita'])) {
  $colname_ambil_berita = $_GET['idberita'];
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_ambil_berita = sprintf("SELECT * FROM artikel WHERE id = %s ORDER BY id ASC", GetSQLValueString($colname_ambil_berita, "text"));
$ambil_berita = mysql_query($query_ambil_berita, $sepolwan_connect) or die(mysql_error());
$row_ambil_berita = mysql_fetch_assoc($ambil_berita);
$totalRows_ambil_berita = mysql_num_rows($ambil_berita);

$colname_comentar_view = "-1";
if (isset($_GET['idberita'])) {
  $colname_comentar_view = $_GET['idberita'];
}
mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
$query_comentar_view = sprintf("SELECT * FROM komentar WHERE idartikel = %s ORDER BY id ASC", GetSQLValueString($colname_comentar_view, "text"));
$comentar_view = mysql_query($query_comentar_view, $sepolwan_connect) or die(mysql_error());
$row_comentar_view = mysql_fetch_assoc($comentar_view);
$totalRows_comentar_view = mysql_num_rows($comentar_view);

$updateSQL = sprintf("UPDATE artikel SET view=%s WHERE id=%s",
                       
					   GetSQLValueString($row_ambil_berita['view']+1, "text"),
                       GetSQLValueString($_GET['idberita'], "text"));
					   
   mysql_select_db($database_sepolwan_connect, $sepolwan_connect);
  $Result1 = mysql_query($updateSQL, $sepolwan_connect) or die(mysql_error());
  
  
?>


<p>
<table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div id="halaman"><div class="jusul"><?php echo $row_ambil_berita['judul']; ?></div><?php if ($totalRows_ambil_berita > 0) { // Show if recordset not empty ?>
     <font size="-5" color="#999999"><?php echo tgl_indo($row_ambil_berita['waktu']); ?> | dilihat: <?php echo $row_ambil_berita['view']; ?> orang | komentar: <?php echo $row_ambil_berita['comment']; ?></font><p><img src="<?php echo $base ?>images/artikel/<?php echo $row_ambil_berita['image']; ?>" width="920" /></p>
      <div style="text-align:justify; margin-bottom:10px"><?php echo $row_ambil_berita['isi']; ?></a></div>
    </div>
    

<table width="200" border="0" align="right" cellpadding="0" cellspacing="0">
      <tr>
        <td align="right"><!-- Tombol Like Facebook -->
<div class="fb-like" data-href="<?php 
  echo curPageURL(); 
?>" data-width="125" data-layout="button_count" data-show-faces="false" data-send="false"></div>
</td>
        <td align="right">
        <div id="fb-root"></div>
<script>
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/id_ID/all.js#xfbml=1';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>
        <!-- Tombol Share Twitter -->
<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php 
  echo curPageURL(); 
?>" data-text="<?php 
  if ($_GET['page']<>'detailberita' and $_GET['page']<>artikel) { 
  		echo str_replace(array('-', '/', '.html'), array(' ', ' | ', ' '), $_GET['page']); 
  } else if ($_GET['page']==detailberita) { 
 		 echo str_replace(array('-', '/', '.html'), array(' ', ' | ', ' '), $_GET['link']); 
  } else if ($_GET['page']==artikel) { 
  		 echo str_replace(array('-', '/', '.html'), array(' ', ' | ', ' '), $_GET['sub']);
  } if ($_GET['page']<>''){ echo "| "; }?> Geriloji Media" data-via="GerilojiMedia" data-lang="id" data-hashtags="GerilojiMedia">Tweet</a>
<script>!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
if(!d.getElementById(id)){
js=d.createElement(s);
js.id=id;js.src=p+'://platform.twitter.com/widgets.js';
fjs.parentNode.insertBefore(js,fjs);
}}(document, 'script', 'twitter-wjs');
</script></td>
        <td align="right"><!-- Tombol Google Plus -->
<g:plusone size="medium" href="<?php 
  echo curPageURL(); 
?>"></g:plusone></td>
      </tr>
    </table> <?php }  
			else { echo "<div align='center'>&rdquo; Maaf Halaman Kosong &rdquo;</div>"; } ?>
</div></td>
  </tr>
</table>

<?php if ($totalRows_comentar_view > 0) { // Show if recordset not empty ?>
<p>
<table width="950" border="0" cellpadding="0" cellspacing="0" align="center">
<tr><td>  <div id="halaman"><div class="jusul">Komentar</strong></div>
          <?php do { ?>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="24%"><strong <?php if ($row_comentar_view['nama']=='administrator'){ echo "style='color:#F00'"; } ?> ><a href="../<?php echo $row_comentar_view['nama']; ?>"><?php echo $row_comentar_view['nama']; ?></a></strong><br /><?php echo tgl_indo($row_comentar_view['waktu']); ?></td>
                <td width="1%"><div style="background: #036; width:2px; height:60px;"></div></td>
                <td width="74%"><div style="margin-left:10px; <?php if ($row_comentar_view['nama']=='administrator'){ echo "color:#F00"; } ?>"><?php echo preg_replace('~@([^\s#@]+)~','<a href="http://geriloji.com/\1" target="_parent">$0</a>', $row_comentar_view['komentar']); ?></div></td>
              </tr>
              <tr>
                <td colspan="3"><div style="background: #FFF2CA; width:100%; height:1px; margin-top:10px; margin-bottom:10px"></div></td>
              </tr>
            </table>
            
     
            <?php } while ($row_comentar_view = mysql_fetch_assoc($comentar_view)); ?>
        </div></td></tr></table></p>
        <?php } // Show if recordset not empty ?>
        <table width="950" border="0" cellpadding="0" cellspacing="0" align="center">
<tr><td>  <div id="halaman"><div class="jusul">Tuliskan Komentar</strong></div>
      <?php if ($_SESSION['MM_Username']){ ?><?php if ($_SESSION['MM_Username']<>'riswan'){ ?><form action="<?php echo $base; ?>detail-<?php echo $_GET['idberita']; ?>/<?php echo $_GET['link']; ?>.html" method="post" name="form1" id="form1">
        <?php if($_POST['nama'] == 'administrator'){ 
	  		echo "<div align='center'>Input nama salah !!</div>"; } ?>
        <table width="100%" align="center">
          <tr valign="baseline">
            <td width="9%" align="left" valign="top" nowrap="nowrap">Komentar:</td>
            <td width="91%">
            <?php if ($_SESSION['MM_Username'] and $row_sesi_member['aktif']<>'ya') { ?><div style="width:100%; padding:5px; background:#F00; color:#FFF " align="center"><strong>Cek Email Anda Untuk Melakukan Aktifasi Akun</strong></div><?php } else { ?><script type="text/javascript">
            $(function() {  
    $("textarea[maxlength]").bind('input propertychange', function() {  
        var maxLength = $(this).attr('maxlength');  
        if ($(this).val().length > maxLength) {  
            $(this).val($(this).val().substring(0, maxLength));  
        }  
    })  
});</script>
            <textarea name="komentar" cols="10" rows="5"  maxlength="255" style="width:80%; height:80px; resize:none"></textarea><br />
*Max : 255 Karakter <?php if ($_POST["komentar"] == "") { ?><span style="color:#F00">(Harus di isi)</span> <?php } ?><?php } ?></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="right">&nbsp;</td>
            <td><input type="submit" value="Kirimkan Komentar" /></td>
          </tr>
        </table>
        <input type="hidden" name="id" value="" />
        <input type="hidden" name="tcomment" value="<?php echo $row_ambil_berita['comment']; ?>" />
        <input type="hidden" name="idartikel" value="<?php echo $row_ambil_berita['id']; ?>" />
        <input type="hidden" name="MM_insert" value="form1" />
    </form><?php } ?>
    <?php } else {
echo "Anda harus <a href='../login.php?url=".$base."detail-".$_GET['idberita']."/".$_GET['link'].".html'>login</a> untuk mengirimkan komentar"; } ?>
   
     </div></td></tr></table>
<?php
mysql_free_result($ambil_berita);

mysql_free_result($comentar_view);
?>
